package com.oss.controller.oss;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oss.common.BaseResponse;
import com.oss.dto.oss.GetByIdDto;
import com.oss.dto.oss.capitalsummary.PageDto;
import com.oss.dto.oss.instrument.AddDto;
import com.oss.dto.oss.instrument.InstrumentListDto;
import com.oss.dto.oss.instrument.PageInstrumentDto;
import com.oss.dto.oss.instrument.UpdateDto;
import com.oss.entity.oss.Instrument;
import com.oss.service.oss.InstrumentService;
import com.oss.vo.oss.instrument.InstrumentLevelVO;
import com.oss.vo.oss.instrument.InstrumentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 合约管理
 */
@RestController
@RequestMapping("/instrument")
public class InstrumentController {
    @Autowired
    InstrumentService instrumentService;

    /**
     * 订阅行情使用
     * @param dto
     * @return
     */
    @PostMapping("/selectByPage")
    public BaseResponse<IPage<Instrument>> selectByPage(@RequestBody @Valid PageInstrumentDto dto){
        return BaseResponse.success(instrumentService.selectByPage(dto));
    }
    // 页面列表查询
    @PostMapping("/selectByList")
    public BaseResponse<List<InstrumentVO>> selectByList(@RequestBody @Valid InstrumentListDto dto){
        return BaseResponse.success(instrumentService.selectByList(dto));
    }
    // 根据父ID获取数据
    @PostMapping("/getByPID")
    public BaseResponse<List<InstrumentVO>> getByPID(@RequestBody @Valid GetByIdDto dto){
        return BaseResponse.success(instrumentService.getByPID(dto.getId()));
    }
    @PostMapping("/getByID")
    public BaseResponse<InstrumentLevelVO> getByID(@RequestBody @Valid GetByIdDto dto){
        return BaseResponse.success(instrumentService.getVOById(dto.getId()));
    }
    @PostMapping("/delete")
    public BaseResponse<Instrument> delete(@RequestBody @Valid GetByIdDto dto){
        return BaseResponse.success(instrumentService.delete(dto.getId()));
    }
    @PostMapping("/add")
    public BaseResponse<String> add(@RequestBody @Valid AddDto dto){
        return instrumentService.add(dto);
    }
    @PostMapping("/update")
    public BaseResponse<Instrument> updateData(@RequestBody @Valid UpdateDto dto){
        return BaseResponse.success(instrumentService.updateData(dto));
    }
    @PostMapping("/getUnExpirationData")
    public BaseResponse<List<Instrument>> getUnExpirationData(){
        return BaseResponse.success(instrumentService.getUnExpirationData());
    }
}